/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hello;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author Sanuel
 */
public class Calculadornotas extends MIDlet implements CommandListener {
    
    private boolean midletPaused = false;
//<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
private Command Salircomando;
private Command Calcular;
private Form form;
private TextField txtt1;
private TextField txtt2;
private TextField txtt3;
private TextField txtpa;
private TextField txtef;
private StringItem txtprot;
private StringItem txtpromf;
//</editor-fold>//GEN-END:|fields|0|

    /**
     * The HelloMIDlet constructor.
     */
    public Calculadornotas() {
    }

//<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
//</editor-fold>//GEN-END:|methods|0|
//<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
/**
 * Initializes the application.
 * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
 */
private void initialize () {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
}//GEN-BEGIN:|0-initialize|2|
//</editor-fold>//GEN-END:|0-initialize|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
/**
 * Performs an action assigned to the Mobile Device - MIDlet Started point.
 */
public void startMIDlet () {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
switchDisplayable (null, getForm ());//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
}//GEN-BEGIN:|3-startMIDlet|2|
//</editor-fold>//GEN-END:|3-startMIDlet|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
/**
 * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
 */
public void resumeMIDlet () {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
}//GEN-BEGIN:|4-resumeMIDlet|2|
//</editor-fold>//GEN-END:|4-resumeMIDlet|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
/**
 * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
 * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
 * @param nextDisplayable the Displayable to be set
 */
public void switchDisplayable (Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
Display display = getDisplay ();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
if (alert == null) {
display.setCurrent (nextDisplayable);
} else {
display.setCurrent (alert, nextDisplayable);
}//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
}//GEN-BEGIN:|5-switchDisplayable|2|
//</editor-fold>//GEN-END:|5-switchDisplayable|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
/**
 * Called by a system to indicated that a command has been invoked on a particular displayable.
 * @param command the Command that was invoked
 * @param displayable the Displayable where the command was invoked
 */
public void commandAction (Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
     
    float t1,t2,t3,ep,ef,pt,pf;
if (displayable == form) {//GEN-BEGIN:|7-commandAction|1|32-preAction
if (command == Calcular) {//GEN-END:|7-commandAction|1|32-preAction
 
    t1 = Float.parseFloat(txtt1.getString());
    t2 = Float.parseFloat(txtt2.getString());
    t3 = Float.parseFloat(txtt3.getString());
    ep = Float.parseFloat(txtpa.getString());
    ef = Float.parseFloat(txtef.getString());
    
     pt = t1*0.20f + t2 *0.35f + t3*0.45f;
     
     pf = pt*0.60f + ep*0.20f + ef*0.20f;
     
     txtprot.setText(String.valueOf(pt));
     txtpromf.setText(String.valueOf(pf));
//GEN-LINE:|7-commandAction|2|32-postAction
 // write post-action user code he
} else if (command == Salircomando) {//GEN-LINE:|7-commandAction|3|19-preAction
                // write pre-action user code here
exitMIDlet ();//GEN-LINE:|7-commandAction|4|19-postAction
                // write post-action user code here
}//GEN-BEGIN:|7-commandAction|5|7-postCommandAction
}//GEN-END:|7-commandAction|5|7-postCommandAction
        // write post-action user code here
}//GEN-BEGIN:|7-commandAction|6|
//</editor-fold>//GEN-END:|7-commandAction|6|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: Salircomando ">//GEN-BEGIN:|18-getter|0|18-preInit
/**
 * Returns an initiliazed instance of Salircomando component.
 * @return the initialized component instance
 */
public Command getSalircomando () {
if (Salircomando == null) {//GEN-END:|18-getter|0|18-preInit
            // write pre-init user code here
Salircomando = new Command ("Exit", Command.EXIT, 0);//GEN-LINE:|18-getter|1|18-postInit
            // write post-init user code here
}//GEN-BEGIN:|18-getter|2|
return Salircomando;
}
//</editor-fold>//GEN-END:|18-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: form ">//GEN-BEGIN:|14-getter|0|14-preInit
/**
 * Returns an initiliazed instance of form component.
 * @return the initialized component instance
 */
public Form getForm () {
if (form == null) {//GEN-END:|14-getter|0|14-preInit
            // write pre-init user code here
form = new Form ("Welcome", new Item[] { getTxtt1 (), getTxtt2 (), getTxtt3 (), getTxtpa (), getTxtef (), getTxtprot (), getTxtpromf () });//GEN-BEGIN:|14-getter|1|14-postInit
form.addCommand (getSalircomando ());
form.addCommand (getCalcular ());
form.setCommandListener (this);//GEN-END:|14-getter|1|14-postInit
            // write post-init user code here
}//GEN-BEGIN:|14-getter|2|
return form;
}
//</editor-fold>//GEN-END:|14-getter|2|



//<editor-fold defaultstate="collapsed" desc=" Generated Getter: Calcular ">//GEN-BEGIN:|31-getter|0|31-preInit
/**
 * Returns an initiliazed instance of Calcular component.
 * @return the initialized component instance
 */
public Command getCalcular () {
if (Calcular == null) {//GEN-END:|31-getter|0|31-preInit
 // write pre-init user code here
Calcular = new Command ("Calcular", Command.OK, 0);//GEN-LINE:|31-getter|1|31-postInit
 // write post-init user code here
}//GEN-BEGIN:|31-getter|2|
return Calcular;
}
//</editor-fold>//GEN-END:|31-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: txtt1 ">//GEN-BEGIN:|22-getter|0|22-preInit
/**
 * Returns an initiliazed instance of txtt1 component.
 * @return the initialized component instance
 */
public TextField getTxtt1 () {
if (txtt1 == null) {//GEN-END:|22-getter|0|22-preInit
 // write pre-init user code here
txtt1 = new TextField ("Ingrese T1", "", 32, TextField.ANY);//GEN-LINE:|22-getter|1|22-postInit
 // write post-init user code here
}//GEN-BEGIN:|22-getter|2|
return txtt1;
}
//</editor-fold>//GEN-END:|22-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: txtt2 ">//GEN-BEGIN:|23-getter|0|23-preInit
/**
 * Returns an initiliazed instance of txtt2 component.
 * @return the initialized component instance
 */
public TextField getTxtt2 () {
if (txtt2 == null) {//GEN-END:|23-getter|0|23-preInit
 // write pre-init user code here
txtt2 = new TextField ("Ingrese T2", "", 32, TextField.ANY);//GEN-LINE:|23-getter|1|23-postInit
 // write post-init user code here
}//GEN-BEGIN:|23-getter|2|
return txtt2;
}
//</editor-fold>//GEN-END:|23-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: txtt3 ">//GEN-BEGIN:|24-getter|0|24-preInit
/**
 * Returns an initiliazed instance of txtt3 component.
 * @return the initialized component instance
 */
public TextField getTxtt3 () {
if (txtt3 == null) {//GEN-END:|24-getter|0|24-preInit
 // write pre-init user code here
txtt3 = new TextField ("Ingrese T3", "", 32, TextField.ANY);//GEN-LINE:|24-getter|1|24-postInit
 // write post-init user code here
}//GEN-BEGIN:|24-getter|2|
return txtt3;
}
//</editor-fold>//GEN-END:|24-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: txtpa ">//GEN-BEGIN:|27-getter|0|27-preInit
/**
 * Returns an initiliazed instance of txtpa component.
 * @return the initialized component instance
 */
public TextField getTxtpa () {
if (txtpa == null) {//GEN-END:|27-getter|0|27-preInit
 // write pre-init user code here
txtpa = new TextField ("Ingrese Parcial", "", 32, TextField.ANY);//GEN-LINE:|27-getter|1|27-postInit
 // write post-init user code here
}//GEN-BEGIN:|27-getter|2|
return txtpa;
}
//</editor-fold>//GEN-END:|27-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: txtef ">//GEN-BEGIN:|28-getter|0|28-preInit
/**
 * Returns an initiliazed instance of txtef component.
 * @return the initialized component instance
 */
public TextField getTxtef () {
if (txtef == null) {//GEN-END:|28-getter|0|28-preInit
 // write pre-init user code here
txtef = new TextField ("Ingrese Final", "", 32, TextField.ANY);//GEN-LINE:|28-getter|1|28-postInit
 // write post-init user code here
}//GEN-BEGIN:|28-getter|2|
return txtef;
}
//</editor-fold>//GEN-END:|28-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: txtprot ">//GEN-BEGIN:|29-getter|0|29-preInit
/**
 * Returns an initiliazed instance of txtprot component.
 * @return the initialized component instance
 */
public StringItem getTxtprot () {
if (txtprot == null) {//GEN-END:|29-getter|0|29-preInit
 // write pre-init user code here
txtprot = new StringItem ("Promedio T", "");//GEN-LINE:|29-getter|1|29-postInit
 // write post-init user code here
}//GEN-BEGIN:|29-getter|2|
return txtprot;
}
//</editor-fold>//GEN-END:|29-getter|2|

//<editor-fold defaultstate="collapsed" desc=" Generated Getter: txtpromf ">//GEN-BEGIN:|30-getter|0|30-preInit
/**
 * Returns an initiliazed instance of txtpromf component.
 * @return the initialized component instance
 */
public StringItem getTxtpromf () {
if (txtpromf == null) {//GEN-END:|30-getter|0|30-preInit
 // write pre-init user code here
txtpromf = new StringItem ("Promedio Final", "");//GEN-LINE:|30-getter|1|30-postInit
 // write post-init user code here
}//GEN-BEGIN:|30-getter|2|
return txtpromf;
}
//</editor-fold>//GEN-END:|30-getter|2|

    /**
     * Returns a display instance.
     * @return the display instance.
     */
    public Display getDisplay() {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable(null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet();
        } else {
            initialize();
            startMIDlet();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
    }
}
